#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

import matplotlib
import matplotlib.pyplot as plt
from math import *


D2R = 2 * pi / 360

# plt.xlim(-3, 3)
# plt.ylim(-3, 3)
plt.gca().set_aspect('equal', adjustable='box')


def degree_2_radian(degree):
    return degree * D2R

def polar_2_xy(r, s):
    ''' '''
    x = r * cos(s)
    y = r * sin(s)
    return x,y

def plot_x_y_axis(max=200):
    a =  [-max, max]
    b =  [0, 0]

    plt.plot(a, b)     # x
    plt.plot(b, a)     # y

def draw_spiral(start=0, ratio=2, n=5):
    '''
        n: 画几圈
        ratio : r/theta (阿基米德螺旋线极坐标 半径/弧度)
        start : 初始点距离x距离
    '''
    xs = []
    ys = []

    for degree in range(0, n * 360, 1):
        d = degree_2_radian(degree) # 弧度
        r = start + ratio * d       # 半径

        print(d, r)
        x, y = polar_2_xy(r, d)

        xs.append(x)
        ys.append(y)

    plt.plot(xs, ys)
    plot_x_y_axis(xs[-1])

    plt.show()

def main():
    print("start main")
    draw_spiral(5, 100, 4)

if __name__ == "__main__":
    main()
